/*
 * One example for NOI CSP-J Lesson 7:
 * <https://courses.fmsoft.cn/plzs/noijunior-graph-and-graph-theory.html>
 *
 * Author: Vincent Wei
 *  - <https://github.com/VincentWei>
 *  - <https://gitee.com/vincentwei7>
 *
 * Copyright (C) 2025 FMSoft <https://www.fmsoft.cn>.
 * License: GPLv3
 */
#include <iostream>           // for std::cout
#include <vector>             // for std::vector

using namespace std;

// 矢量构成的矢量可用于矩阵的表达。
using adjacency_matrix = vector<vector<int>>;

void addEdge(adjacency_matrix &graph, int i, int j)
{
    graph[i][j] = 1;
    graph[j][i] = 1;
}

// 亦可通过重载左移运算符 << 实现矩阵的输出
void dumpMatrix(ostream &os, const adjacency_matrix &graph)
{
    int V = graph.size();
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < V; j++)
            os << graph[i][j] << " ";
        os << endl;
    }
}

int main()
{
    // 顶点数量
    int V = 4;

    // 在使用邻接矩阵表达图时，行列数一定是一样的。
    adjacency_matrix graph(V, vector<int>(V, 0));

    addEdge(graph, 0, 1);
    addEdge(graph, 0, 2);
    addEdge(graph, 1, 2);
    addEdge(graph, 2, 3);

    /* 如果预先知道所有的边，亦可使用下面的方法初始化：
     adjacency_matrix graph = {
         { 0, 1, 0, 0 },
         { 1, 0, 1, 0 },
         { 0, 1, 0, 1 },
         { 0, 0, 1, 0 }
    }; */

    cout << "Adjacency Matrix Representation:" << endl;
    dumpMatrix(cout, graph);

    return 0;
}
